import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)

export const constantRoutes = [

  {
    path: '',
    redirect: '/home'
  },

  {
    path: '/home',
    component: () => import('@/views/news/home'),
    meta: {
      keepAlive: true
    }
  },

  {
    path: '/news',
    component: () => import('@/views/news/news')
  },

  {
    path: '/my',
    component: () => import('@/views/news/my')
  },

  {
    path: '/register',
    component: () => import('@/views/news/register')
  },

  {
    path: '/list',
    component: () => import('@/views/news/list')
  },

  {
    path: '/401',
    component: () => import('@/views/401'),
    hidden: true
  },

  {
    path: '/404',
    component: () => import('@/views/404'),
    hidden: true
  }
]

const createRouter = () => new Router({
  mode: 'history', // require service support
  // scrollBehavior: () => ({ y: 0 }),
  routes: constantRoutes
})

export const router = createRouter()

// Detail see: https://github.com/vuejs/vue-router/issues/1234#issuecomment-357941465
export function resetRouter() {
  const newRouter = createRouter()
  router.matcher = newRouter.matcher // reset router
}

export default router
